<?php
/**
 * 案例修改管理页面
 * author:wang
 * mail:970633164@qq.com
 */
define("PHP_IN", true);
require "../include/init.php";
require "checklogin.php";
require ROOT_PATH."cms/smart_connection.php";

$caseid = isset($_GET['caseid']) ? $_GET['caseid'] : 0;
$page = isset($_GET['page']) ? $_GET['page'] : 1;

$sql = "SELECT * FROM case_type";   //案例分类选择
$result = $db->query($sql);
$case_type = $db->fetch_all($result);

$sql = "SELECT * FROM cases WHERE caseid = $caseid";
$result = $db->query($sql);
$cases = $db->fetch_one($result);

if (isset($_POST['dosubmit'])) {
    $caseid = $_POST['caseid'];
    $title = $_POST['title'];
    $intro = $_POST['intro'];
    $content = isset($_POST['editorValue']) ? $_POST['editorValue'] : "";
    $url = $_POST['url'];
    $isdisplay = $_POST['isdisplay'];
    $case_type = $_POST['case_type'];
    $t = time();
    $thumbname = $_POST['thumb'];
    if (isset($_FILES)) {
        if ($_FILES['photo']['error'] == 0) {
            unlink($cases_thumb_up . $thumbname);
            $filename = file_ext($_FILES['photo']['name']);
            $thumbname = $t . rand(1, 10000) . $filename;
            $path = $cases_thumb_up . $thumbname;
            $upload = move_uploaded_file($_FILES['photo']['tmp_name'], $path);
        }
    }

    $sql = "UPDATE cases SET title='$title',intro='$intro',content='$content',url='$url',
          cid='$case_type',thumb='$thumbname',isdisplay='$isdisplay' WHERE caseid = $caseid";
    $result = $db->query($sql);
    if ($result) {
        alert("修改成功", "case_list.php?page=".$page);
    } else {
        alert("修改失败");
    }
}


$smarty->assign("case_type",$case_type);
$smarty->assign("cases",$cases);
$smarty->assign("page",$page);

$smarty->display("case_edit.tpl");
$db->close();
?>
